<?php
/* EXEMPLO DE USO

	$objForm = new Formulario("post", "home.php", "config", "Fieldset Senha", "admin");
	//Input
	$objForm->addInput("Nova Senha:", "senha", "text", "", "input-menor", "");
	//TextArea
	$objForm->addTextArea("Titulo TextArea:", "nome", "70", "5", "valor", "", "");
	//Select
	$objForm->addOption("valorOption", "", "jamerson");
	$objForm->addOption("valorOption", "selected=\"selected\"", "Fabricio");
	$objForm->addOption("valorOption", "", "Inacio");
	$objForm->addOption("valorOption", "", "Ramalho");
	$objForm->addSelect("nomeSelect", "", "");
	//Botao Enviar
	$objForm->addBt("submit", "Inserir", "botaoForm");
	//Exibe o formulario
	$objForm->show();
*/

//Inclui a classe Model
include_once("Model.class.php");

class Formulario extends Model{
		
	//Variaveis necessarias
    public $methodForm;
    public $actionForm;
    public $nameForm;
	public $fieldsetForm;
	public $classForm;
	public $options;
   
   //metodo construtor
    function __construct($methodForm, $actionForm, $nameForm, $fieldsetForm, $classForm){
    	//inicializa o codigo html em branco
		$this->htmlCode = ""; 
		//inicializa o codigo do option do select em branco
		$this->options  = "";
       	//seta os valores default
		$this->methodForm   = $methodForm;
       	$this->actionForm   = $actionForm;
		$this->nameForm     = $nameForm;
		$this->fieldsetForm = $fieldsetForm;
       	$this->classForm    = $classForm;
    }
   
    //adiciona um input
    function addInput($label="", $name, $type, $value="", $class="", $events="", $title="", $maxlength=""){
    	//Adiciona o codigo ao codigo do form
		$this->htmlCode.= "<li><label for=\"".$name."\"><strong>".$label."</strong></label>\n";
    	$this->htmlCode.= "<input type=\"".$type."\" name=\"".$name."\" id=\"".$name."\" value=\"".$value."\" title=\"".$title."\" class=\"".$class."\" maxlength=\"$maxlength\" $events />\n";
		$this->htmlCode.= "</li>\n";
    }
		
	//adiciona um select
    function addSelect($label="", $name, $class="", $events="", $title=""){
    	//Adiciona o codigo dos options ao codigo do select
    	$this->htmlCode.= "<li><label for=\"".$name."\"><strong>".$label."</strong></label>\n";
    	$this->htmlCode.= "<select name=\"".$name."\" id=\"".$name."\" title=\"".$title."\" class=\"".$class."\" ".$events." />";
		$this->htmlCode.= $this->options;
		$this->htmlCode.= "</select></li>\n";
		
		// Zera o options para inclusao de um novo select
		$this->options = "";
    }
		
	//adiciona um option ao select
	function addOption($value="", $selected=false, $texto=""){
		//gera o codigo do option
		$selected ? $selected = "selected=\"selected\"" : $selected = "";
     	$this->options.= "<option value=\"".$value."\" ".$selected.">".$texto."</option>\n";
    }
		
    //adiciona um text area
   	function addTextArea($titulo="", $name, $cols="", $rows="", $value="", $class="", $events="", $title=""){
	 	//Adiciona o codigo ao codigo do form
		$this->htmlCode.= "<li><label for=\"".$name."\"><strong>".$titulo."</strong></label>\n";
     	$this->htmlCode.= "<textarea name=\"".$name."\" id=\"".$name."\" cols=\"".$cols."\" rows=\"".$rows."\" title=\"".$title."\" class=\"".$class."\" $events>".$value."</textarea>\n";
		$this->htmlCode.= "</li>\n";
    }
		
	//adiciona um botao
	function addBt($type, $value="", $class="", $title=""){
		//Adiciona o codigo ao codigo do form
    	$this->htmlCode.= "<li><input type=\"".$type."\" value=\"".$value."\" name=\"".$value."\" title=\"".$title."\" class=\"".$class."\" /></li>\n";
    }
    
    //adiciona um campo Hidden
    function addHidden($name, $value=""){
    	//Adiciona o codigo ao codigo do form
    	$this->htmlCode.= "<input type=\"hidden\" name=\"".$name."\" id=\"".$name."\" value=\"".$value."\" />\n";
    }

   //exibe o codigo, sobrescreve e chama a omoetodo da classe mae
    function show()
    {
    	$form = "<form method=\"".$this->methodForm."\" action=\"".$this->actionForm."\" name=\"".$this->nameForm."\" class=\"".$this->classForm."\">\n";
		$form.= "<fieldset><legend>".$this->fieldsetForm."</legend><ul>\n";
    	$form.= $this->htmlCode;
		$form.= "</ul></fieldset>\n";
    	$form.= "</form>\n";
			
		//inclui o valor da variavel $form na variavel $htmlCode
		$this->htmlCode = $form;
			
        //chama o metodo da classe mae
        parent::show();
    }


}
?>